<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Fang;
use App\Models\Fangattr;

class FangController extends Controller
{
    public function recommend(Request $request)
    {
        # 获取数据
        $data = Fang::select(["id", "fang_pic"])->where("is_recommend", "1")->limit(6)->get();
        return ["status" => 0, "msg" => "获取成功", "data" => $data];
    }
    public function attr(Request $request)
    {
        $field_name = $request->get("field_name");
        // dump($field_name);die;
        $data = Fangattr::all()->toArray();
        // dump($data);die; 
        $data = subTreeName($data);
        // dump($data);die;
        return ["status" => 0, "msg" => "获取成功", "data" => $data[$field_name]];
    }
    # 房源列表
    public function index(Request $request)
    {
        $data = Fang::select([
            "id",
            "fang_pic",
            "fang_name",
            "fang_rent",
            "fang_floor",
            "fang_shi",
            "fang_ting",
            "fang_wei",
            "fang_rent_class",
            "fang_build_area"
        ])->paginate(config("app.pagsize"));
        return ["status" => 0, "msg" => "获取成功", "data" => $data];
    }
}
